package es

import (
	"bytes"
	"context"
	"encoding/json"
	"github.com/elastic/go-elasticsearch/v7/esapi"
	"github.com/zeromicro/go-zero/core/logx"
	"goods_srv/model/mysql"

	"strconv"
)

// 同步es
func SyncEs(goods *mysql.GoodsZye3) {
	data, err := json.Marshal(goods)
	if err != nil {
		logx.Error("es1 同步失败", err)
		return
	}
	// Set up the request object.
	req := esapi.IndexRequest{
		Index:      "test",
		DocumentID: strconv.Itoa(int(goods.ID)),
		Body:       bytes.NewReader(data),
		Refresh:    "true",
	}
	// Perform the request with the client.
	res, err := req.Do(context.Background(), Es)
	if err != nil {
		logx.Error("es2 同步失败", err)
		return
	}
	defer res.Body.Close()

}
